<?php
$title="添加新商品";
$css="productAdd.css";
include_once 'common/AdminTop.php';
include_once 'authentic.php';
include_once '../Class/DB.php';
$db=new DB();
$classes=$db->get_bigClass_smallClass();
$str=json_encode($classes);
$p_name=$_POST["p_name"];
if(!isset($p_name))
{
	
}
else if($p_name=="")
{
	?>
	<script language="JavaScript">
	alert("商品名称不能为空！");
	window.location.href="productAdd.php";
	</script>	
	<?php	
}

$ori_price=$_POST["ori_price"];
if(!isset($ori_price))
{
	//$ori_price=$AProduct["ori_price"];
	
}
else if($ori_price=="")
{
	?>
	<script language="JavaScript">
	alert("原价格不能为空！");
	window.location.href="productAdd.php";
	</script>	
	<?php
}

$act_price=$_POST["act_price"];
if(!isset($act_price))
{
	//$act_price=$AProduct["act_price"];
	
}
else if($act_price=="")
{
	?>
	<script language="JavaScript">
	alert("实际价格不能为空！");
	window.location.href="productAdd.php";
	</script>	
	<?php
}

$count=$_POST["count"];
if(!isset($count))
{
	//$count=$AProduct["count"];
	
}
else if($count=="")
{
	?>
	<script language="JavaScript">
	alert("数量不能为空！");
	window.location.href="productAdd.php";
	</script>	
	<?php
}

$onTime=$_POST["onTime"];
if(!isset($onTime))
{
	//$onTime=$AProduct["onTime"];
	
}
else if($onTime=="")
{
	?>
	<script language="JavaScript">
	alert("上架时间不能为空！");
	window.location.href="productAdd.php";
	</script>	
	<?php
}

$b_name=$_POST["classify1"];
if(!isset($b_name))
{
	//$s_class=$db->get_tid_types($AProduct["type"]);
	//$b_class=$db->get_tid_types($s_class[0]["parent"]);
	//$b_name=$b_class[0]["name"];
	//echo $b_class[0]["name"];
	//exit();
}
else if($b_name=="0"){
	
	?>
	<script language="JavaScript">
	alert("类型不能为所有类型！");
	window.location.href="productAdd.php";
	</script>	
	<?php
	exit();
}

$s_name=$_POST["classify2"];
if (!isset($s_name))
{
	//$s_name=$s_class[0]["name"];
	//echo $s_name;
	//exit();
}
else if($s_name=="0")
{
	?>
	<script language="JavaScript">
	alert("类型不能为所有类型！");
	window.location.href="productAdd.php";
	</script>	
	<?php
	exit();
}

$picurl=$_POST["picurl"];
if(!isset($picurl))
{
//$picurl=$AProduct["pic_url"];

}
else if($picurl==""){

	$picurl='../image/product_img/item_none.png';
	//echo $picurl;
	//exit();
}
else {
	$picurl='../image/product_img/'.$picurl;
}

$meta=$_POST["meta"];
if(!isset($meta))
{
//$meta=$AProduct["meta"];
}else if($meta=="")
{
	?>
	<script language="JavaScript">
	alert("搜索关键字不能为空！");
	window.location.href="productAdd.php";
	</script>	
	<?php
	exit();
}

$introduction=$_POST["introduction"];
if(!isset($introduction))
{

}else if($introduction=="")
{
	?>
	<script language="JavaScript">
	alert("商品简介不能为空！");
	window.location.href="productAdd.php";
	</script>	
	<?php
	exit();
}


if(isset($_POST["classify2"]))//说明管理员按了保存按钮
{
	$s_tid=$db->get_name_tid($s_name, "s");
	$db->AddProduct($p_name,$ori_price,$act_price,$count,$onTime,$s_tid,$picurl,$meta,$introduction);
	?>
	<script language="JavaScript">
	window.location.href="productList.php";
	</script>	
	<?php 	
	}
	?>
<script language="JavaScript">
var str='<?php print_r($str);?>';
//将PHP传来的字符串还原成数组
var classes = JSON.parse(str);
</script>
<script src="../js/productAdd.js" type="text/javascript"></script>
<div class="block_context" id="modify_block" align="center">
<p style="color:red">产品详细信息</p>
				<form action="productAdd.php" method="post">
					<table>
						<tr>
							<th class="t1" >
							</th>
							<th class="t2">
							</th>	
						</tr>
						<tr>
							<td style="text-align: right;">
							<b>商品名称:</b>
							</td>
							<td style="text-align: left;padding-left: 16px"><input type="text" style="width:150px;" name="p_name"  value=""/></td>
						</tr>
						<tr>
							<td style="text-align: right;">
							<b>原价:</b>
							</td>
							<td style="text-align: left;"><label style="color:orange;">￥</label><input type="text" style="width:80px" name="ori_price" value=""></td>
						</tr>
						<tr>
							<td style="text-align: right;">
							<b>实价:</b>
							</td>
							<td style="text-align: left;"><label style="color:orange;">￥</label><input type="text" style="width:80px" name="act_price" value=""></td>
						</tr>
						<tr>
							<td style="text-align:right;">
							<b>数量:</b>
							</td>
							<td style="padding-left:16px;text-align:left;"><input type="text" style="width:80px;" name="count"  value=""/></td>
						</tr>
						<tr>
							<td style="text-align: right;">
							<b>上架时间:</b>
							</td>
							<td style="padding-left:16px;text-align: left;">
								<input style="width:80px;" type="text" name="onTime" value=""/>
							</td>
						</tr>	
						<tr>
							<td style="text-align: right;">
							<b>商品类型:</b>
							</td>
							<td style="padding-left:16px;text-align: left;">
							
								<select name="classify1" onchange="on_select(this)" id="big">
								<option value="0">所有分类</option>
								<?php 
									$c_name=$db->get_parent_types(0);
									$i=0;
									while(isset($c_name[$i])){
	       								
	       							?>
	        						<option value="<?php echo $c_name[$i]["name"];?>"><?php echo $c_name[$i]["name"];?></option>
								<?php 	
									$i++;
									}
									?>
								</select>
								<select name="classify2" id="small">
			                     <option value="0">所有子分类</option>
								</select>
							</td>
						</tr>
						<tr>
						<td style="text-align: right;">
							<b>图片位置:</b>
						</td>
						<td style="padding-left:16px;text-align: left;">
						<input type="file" style="color:red;" name="picurl"  value=""/>		
						</td>
						</tr>
						<tr>
						<td style="text-align: right;">
							<b>关键字:</b>
						</td>
						<td style="padding-left:16px;text-align: left;">
						<input type="text"  style="width:250px;" name="meta"  value=""/>		
						</td>
						</tr>
						<tr>
						<td style="text-align: right;">
							<b>商品简介:</b>
						</td>
						<td style="padding-left:16px;text-align: left;">
						<textarea name="introduction" style="width:250px;height:200px;font-size:12px;"></textarea>		
						</td>
						</tr>
						</table>
						<p><input type="submit" value="添加" />
						</p>
				</form>
			</div>
<?php 
include_once 'common/AdminTail.php';
?>
